class AnaFile:
    def __init__(self, content):
        self.content = content
        self.group = "connect"
        self.name = "sensor"
        self.sensor_ids = []

    def ana_file(self):
        for data in self.content:
            if data.get("group") == self.group:
                controls = data.get("controls")
                for control in controls:
                    if control.get("attribute") == "sensor":
                        value_str = control.get("value")
                        sensor_ids = self.__get_sensor_ids(value_str)
                        for sensor_id in sensor_ids:
                            self.sensor_ids.append(sensor_id)
        return self.sensor_ids

    def __get_sensor_ids(self, value_str):
        sensor_ids = []
        # 只包含，
        if value_str:
            if not value_str.__contains__("-") and value_str.__contains__(","):
                values = value_str.split(",")
                for value in values:
                    try:
                        sensor_ids.append(int(value))
                    except:
                        pass
            # 只包含-
            elif value_str.__contains__("-") and not value_str.__contains__(","):
                num = value_str.split("-")
                try:
                    start = int(num[0])
                    end = int(num[1]) + 1
                    for value in range(start, end):
                        sensor_ids.append(value)
                except:
                    pass
            # 两者都有
            elif value_str.__contains__("-") and value_str.__contains__(","):
                items = value_str.split(",")
                for item in items:
                    if item.__contains__("-"):
                        sensor_ids.extend(self.__get_sensor_ids(item))
                    else:
                        try:
                            sensor_ids.append(int(item))
                        except:
                            pass
            else:
                if value_str:
                    try:
                        sensor_ids.append(int(value_str))
                    except:
                        pass
        return sensor_ids

